function pause(millisecondi) {
	var now = new Date();
	var exitTime = now.getTime() + millisecondi;

	while(true) {
		now = new Date();
		if(now.getTime() > exitTime) return;
	}
}

function createRequestObject() {
     var ro;
     var browser = navigator.appName;
     if(browser == "Microsoft Internet Explorer"){
          ro = new ActiveXObject("Microsoft.XMLHTTP");
     }else{
          ro = new XMLHttpRequest();
     }
     return ro;
}

var http = createRequestObject();

function load_event_logs(event_id) {

	div_destination = 'event_logs_' + event_id;

	if ( document.getElementById(div_destination).innerHTML.length == 0 ) {
		sndReq('/rpc_event_logs','event_id=' + event_id, div_destination);
	}

	toggleLayer(div_destination);
}

function load_errata_details(hostname, pkg_name) {

	div_destination = 'pkg_upd_' + pkg_name;

	if ( document.getElementById(div_destination).innerHTML.length == 0 ) {
		sndReq('/host/rpc_errata_details','hostname=' + hostname + '&pkg_name=' + pkg_name, div_destination);
	}

	toggleLayer(div_destination);
}

function rpc_star_log(log_id) {
     http.open('get', '/rpc_star_log?log_id=' + log_id);
     http.onreadystatechange = rpc_star_log_handler;
     http.send(null);
}

function rpc_star_log_handler() {

	if(http.readyState != 4 || http.responseText.length == 0) {
		return -1;
	}

	var update = new Array();
	var response = http.responseText;

	if(response.indexOf('|') != -1) {

		var update = new Array();

		update = response.split('|');

		document.getElementById('star_' + update[0]).src = update[1];
	}
}

function rpc_parsing_redirect() {

	http.open("get","/rpc_parsing_redirect");
	http.onreadystatechange = rpc_parsing_redirect_handler;
	http.send(null);
}

function rpc_parsing_redirect_handler() {
	if(http.readyState == 4 && http.responseText.length > 0) {
          document.location = http.responseText;
	}
}

function sndReq(rpc_handler, arguments, dest) {
     http.open('get', rpc_handler + '?' + arguments);
     http.onreadystatechange = handleResponse;
     http.send(null);
     http.div_destination = dest;
     document.getElementById(dest).innerHTML = '<img src="/static/images/loading.gif" alt="Loading... please wait.">';
}

function handleResponse() {
     if(http.readyState == 4){
          document.getElementById(http.div_destination).innerHTML = http.responseText;
          return;
          var response = http.responseText;
          var update = new Array();

          if(response.indexOf('|') != -1) {
               update = response.split('|');
               document.getElementById("prova").innerHTML = update[1];
/*               document.getElementById("rawlog_event_" + update[0]).innerHTML = update[1]; */
          }
     }
}
